home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / GETMEM.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  3KB  |  122 lines

  1. cseg    segment para public 'code'
  2. org    100h
  3. getmem    proc far
  4.  
  5. intaddr equ 60h*4        ; interrupt address - int 60 hex
  6.  
  7. ; Memory-resident program to get and hold a block of memory.
  8. ; To reserve a block of memory, enter 'GETMEM nn', where nn is the
  9. ; number of KB to be allocated. For example, 'GETMEM 32' reserves 32KB.
  10. ; NN can be from 1 to 63. The address of the block is saved at interrupt
  11. ; 60h (0:180h - 0:183h), with the length in the  first word, and the segment
  12. ; in the second word.
  13. ; A '/x' option can be used to keep the program from allocating memory if
  14. ; a block of memory is already allocated.
  15.  
  16.     assume cs:cseg,ds:cseg,ss:nothing,es:nothing
  17.  
  18. p000:                ; read command line
  19.     mov dx,offset copyr
  20.     call p100        ; print copyright
  21.     mov si,80h        ; point to start of command line
  22.     mov ch,0
  23.     mov cl,[si]        ; get length
  24.     mov ax,0
  25.     mov bx,0
  26. p010:    inc si            ; point to next character
  27.     mov bl,[si]        ; get the character
  28.     cmp bl,'/'              ; is it a slash?
  29.     jnz p015        ; no
  30.     mov bh,[si+1]        ; get next character
  31.     cmp bh,'x'              ; is it 'x'?
  32.     jz p012         ; yes
  33.     cmp bh,'X'              ; is it 'X'?
  34.     jz p012         ; yes
  35.     mov bh,0
  36.     jmp p015
  37.  
  38. p012:    mov norerun,bh        ; set rerun flag
  39.     mov bh,0
  40.  
  41. p015:    cmp bl,'0'              ; is it less than zero?
  42.     jb p020         ; yes
  43.     cmp bl,'9'              ; is it greater than nine?
  44.     ja p020         ; yes
  45.     sub bl,'0'              ; convert to binary
  46.     push cx         ; save cx
  47.     mov cx,10
  48.     mul cx            ; multiply current ax by 10
  49.     pop cx
  50.     add ax,bx        ; add latest digit
  51. p020:    loop p010        ; all done?
  52.  
  53.     cmp ax,1        ; is memory less than 1?
  54.     jb p090         ; yes
  55.     cmp ax,63        ; is memory greater than 63?
  56.     ja p090         ; yes
  57.     push ax         ; save ax
  58.  
  59.     aam            ; set up message
  60.     xchg ah,al
  61.     add ax,3030h        ; make it ascii
  62.     cmp al,30h        ; leading zero?
  63.     jnz p030        ; no
  64.     mov al,20h        ; make it a space
  65.  
  66. p030:    mov msg1mem,ax        ; move to message area
  67.  
  68.     pop ax            ; restore ax
  69.     mov cl,10
  70.     sal ax,cl        ; convert to KB
  71.     mov memsize,ax        ; save memory size
  72.  
  73.     push es         ; set interrupt 60h
  74.     mov ax,0
  75.     mov es,ax
  76.     mov di,intaddr        ; interrupt address
  77.     mov al,norerun        ; is /x option present?
  78.     cmp al,0
  79.     jz p050         ; no
  80.  
  81.     mov ax,es:[di]
  82.     cmp ax,0        ; any memory reserved?
  83.     jz p050         ; no
  84.     pop es
  85.     int 20h         ; yes - terminate
  86.  
  87. p050:    mov ax,memsize        ; length of block
  88.     push cs
  89.     pop bx            ; code segment
  90.     mov es:[di],ax        ; modify interrupt
  91.     mov es:[di+2],bx
  92.     pop es
  93.     mov dx,offset msg1    ; print message
  94.     call p100
  95.     mov dx,memsize        ; set block size
  96.     int 27h         ; terminate and stay resident
  97.  
  98. p090:                ; print error message
  99.     mov dx,offset msg2
  100.     call p100
  101.     int 20h         ; terminate
  102.  
  103. p100    proc near        ; print message
  104.     push ax
  105.     mov ah,9
  106.     int 21h
  107.     pop ax
  108.     ret
  109. p100    endp
  110.  
  111. memsize dw 0            ; requested memory size
  112. norerun db 0            ; rerun flag - non-zero if /x option
  113. copyr    db 'GETMEM - Copyright 1983 Data Base Decisions',10,13,'$'
  114. msg1    db 'Reserving '
  115. msg1mem dw '..'
  116.     db ' KB of memory.',10,13,'$'
  117. msg2    db 'Missing/invalid memory specification',7,10,13,'$'
  118.  
  119. getmem    endp
  120. cseg    ends
  121. end    getmem
  122.